package com.easyaop.core.event;

import java.util.ArrayList;
import java.util.List;

public class EventSource {
    public static final EventSource EVENT_SOURCE = new EventSource();

    private final List<EventListener> listeners = new ArrayList<>();

    // 添加事件监听器
    public void addEventListener(EventListener listener) {
        listeners.add(listener);
    }

    // 移除事件监听器
    public void removeEventListener(EventListener listener) {
        listeners.remove(listener);
    }

    // 触发事件
    public void trigger(Event event) {
        for (EventListener listener : listeners) {
            listener.onEvent(event);
        }
    }

    static {
        EVENT_SOURCE.addEventListener(new PointcutEventListener());
    }
}
